package mo.tags.greedy;

import java.util.Arrays;

public class L45 {

    public int jump(int[] nums) {
        int n = nums.length;
        int[] dp = new int[n];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = 0;
        for (int i = 0; i < n; i++) {
            for (int j = i+1; j < i+1+nums[i] && j < n; j++) {
                dp[j] = Math.min(dp[j], dp[i] + 1);
                if (j == n - 1) {
                    return dp[j];
                }
            }
        }
        return dp[n-1];
    }

    public static void main(String[] args) {
        L45 test = new L45();
        System.out.println(test.jump(new int[]{1,2,1,1,1}));
    }

}
